import numpy as np

#查询连续0的个数和位置
#输入[0,1,1,0,0,0,1,0]
#输出[1,0,0,3,0,0,0,1]
def count_zero(list):
    res = np.zeros(len(list) + 1)
    index = 0
    num = 0
    for i in range(len(list)):
        if list[i] == 0:
            num += 1
        else:
            res[index] = num
            index = i + 1
            num = 0
    res[index] = num
    return res[0:len(list)]

#查询 路由 链路对应slot或运算的最终结果
# link是一个[链路数量，slot数量]的数组，route表示要查询的路由中链路编号
# 输出最终slot结果  [0,0,1,0,3,0,0,1,0]
def get_route_slot_final(link, route):
    link_res = np.zeros(len(link[0]))
    for i in route:
        for j in range(len(link[0])):
            link_res[j] = int(link_res[j]) | int(link[i][j])
    link_zero_res = count_zero(link_res)
    return link_zero_res